home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / EXEINFO.ZIP / EXE.C next >
C/C++ Source or Header  |  1997-01-02  |  3KB  |  97 lines

  1. /*
  2.      Program to list header of EXE files
  3.  
  4.      Written by David Ashley  970102
  5.              dash@netcom.com
  6. */
  7.  
  8. struct exe
  9. {
  10.     short signature;
  11.     short lastpagebytes;
  12.     short numpages;
  13.     short numrelocitems;
  14.     short headersize;
  15.     short minalloc;
  16.     short maxalloc;
  17.     short initialss;
  18.     short initialsp;
  19.     short checksum;
  20.     short initialip;
  21.     short initialcs;
  22.     short relocoffset;
  23.     short overlaynum;
  24. };
  25. #define HEADERSIZE 16384
  26. char header[HEADERSIZE];
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char *argv[];
  31. {
  32. int infile;
  33. struct exe *anexe;
  34. int i,j;
  35. unsigned short *lp;
  36. char name[128];
  37. long progbase;
  38. short val;
  39. long longoff;
  40.  
  41.     if(argc<2)
  42.     {
  43.         printf("Need EXE filename as parameter\n");
  44.         exit();
  45.     }
  46.     strcpy(name,argv[1]);
  47.     infile=fopen(name,"rb");
  48.     if(!infile) strcat(name,".exe");
  49.     infile=fopen(name,"rb");
  50.     if(!infile)
  51.     {
  52.         printf("Cannot open %s\n",argv[1]);
  53.         exit();
  54.     }
  55.     read(infile,header,HEADERSIZE);
  56.     anexe=header;
  57.     printf("%04x Signature\n",anexe->signature);
  58.     printf("%04x Number of bytes in last page\n",anexe->lastpagebytes);
  59.     printf("%04x Number of 512-byte pages (including last page)\n",anexe->numpages);
  60.     printf("%04x Number of relocation items in the relocation table\n",anexe->numrelocitems);
  61.     printf("%04x Size of header, in paragraphs\n",anexe->headersize);
  62.     printf("%04x Minimum allocation, in paragraphs\n",anexe->minalloc);
  63.     printf("%04x Maximum allocation, in paragraphs\n",anexe->maxalloc);
  64.     printf("%04x Initial SS value (SS=this + 10h + DS)\n",anexe->initialss);
  65.     printf("%04x Initial SP value\n",anexe->initialsp);
  66.     printf("%04x Checksum (ignored by DOS and usually not set)\n",anexe->checksum);
  67.     printf("%04x Initial IP value\n",anexe->initialip);
  68.     printf("%04x Initial CS value (CS=this + 10h + DS)\n",anexe->initialcs);
  69.     printf("%04x Byte offset to relocation table\n",anexe->relocoffset);
  70.     printf("%04x Overlay number\n",anexe->overlaynum);
  71.     progbase=anexe->headersize<<4;
  72.     lp=header+anexe->relocoffset;
  73.     i=anexe->numrelocitems;
  74. /*
  75.     if(i)
  76.     {
  77.         printf("Relocation items: each of the form xxxx:yyyy=zzzz\n");
  78.         printf("EXE file after header gets loaded to DS+10h:0\n");
  79.         printf("At each word pointed to by DS+10h+xxxx:yyyy, add DS+10h.\n");
  80.         printf("Original value of word is zzzz.\n");
  81.     }
  82. */
  83.     j=0;
  84.     while(i--)
  85.     {
  86.         longoff=*lp+((long)lp[1]<<4L);
  87.         lseek(infile,longoff+progbase,0);
  88.         read(infile,&val,2);
  89.         printf("%04x:%04x=%04x",lp[1],*lp,val);
  90.         lp+=2;
  91.         j++;
  92.         if(i && j<4) putchar(' '); else putchar('\n');
  93.         if(j==4) j=0;
  94.     }
  95.     fclose(infile);
  96. }
  97.